﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class InteractStarManager : MonoBehaviour {
    private static InteractStarManager _instance;
    public static InteractStarManager Instance
    {
        get
        {
            return _instance;
        }
    }
    private InteractStarManager()
    {
        _instance = this;
    }

    public GameObject Explore;
    public GameObject Colonize;
    public int ColonizePrice
    {
        get
        {
            return 2 * (ControlCenter.Instance.PlanetsCount[ControlCenter.Instance.PlayerIdNow - 1]);
        }
    }
    public GameObject Contact;
    public GameObject Destroyer;
    public int DestroyTimes;
    public int DestroyPrice
    {
        get
        {
            return (ControlCenter.Instance.PlanetsCount[ControlCenter.Instance.PlayerIdNow - 1]) + DestroyTimes;
        }
    }

    [HideInInspector]
    public GameObject TargetStar;

    void Update()
    {
        SetInteractable();
        SetData();
    }

    void SetData()
    {
        Explore.transform.Find("Info/Text").GetComponent<Text>().text = "1";
        Colonize.transform.Find("Info/Text").GetComponent<Text>().text = ColonizePrice.ToString();
        Contact.transform.Find("Info/Text").GetComponent<Text>().text = "1";
        Destroyer.transform.Find("Info/Text").GetComponent<Text>().text = DestroyPrice.ToString();
    }
    void SetInteractable()
    {
        SetInter(Explore, TargetStar.GetComponent<PlanetInteract>().CanBeObserve);
        SetInter(Colonize, TargetStar.GetComponent<PlanetInteract>().CanBeColonized);
        SetInter(Contact, TargetStar.GetComponent<PlanetInteract>().CanBeContact);
    }

    void SetInter(GameObject obj, bool Inter)
    {
        float Alph;
        if (Inter)
            Alph = 1;
        else
            Alph = 0.5f;
        obj.GetComponent<Image>().color = new Color(1, 1, 1, Alph);
        obj.transform.Find("Info/Image").GetComponent<Image>().color = new Color(1, 1, 1, Alph);
        obj.transform.Find("Info/Text").GetComponent<Text>().color = new Color(1, 1, 1, Alph);
        obj.transform.Find("Info/Text1").GetComponent<Text>().color = new Color(1, 1, 1, Alph);
        obj.GetComponent<Button>().interactable = Inter;
    }

    public void ToObserve()
    {
        TargetStar.GetComponent<PlanetInteract>().Observe();
    }
    public void ToColonize()
    {
        TargetStar.GetComponent<PlanetInteract>().Colonize(ColonizePrice);
    }
    public void ToContact()
    {
        TargetStar.GetComponent<PlanetInteract>().StartContact();
    }
    public void ToDestroy()
    {
        TargetStar.GetComponent<PlanetInteract>().Destroyer(DestroyPrice);
    }

}
